package com.twu.biblioteca;

import java.util.ArrayList;

/**
 * Created by Nishi on 9/1/14.
 */
public class Customer {
    String library_number;
    String name;
    String emailID;
    String phone_Number;
    String password;
    ArrayList<String> checkedOutBooks;

    public Customer( String library_number, String name, String emailID, String phone_Number, String password){
        this.library_number = library_number;
        this.name = name;
        this.emailID = emailID;
        this.phone_Number =phone_Number;
        this.password = password;
        checkedOutBooks = new ArrayList<String>();
    }
    public Customer(){

    }
    public Customer(String library_number, String password){
        this.library_number = library_number;
        this.password = password;
        checkedOutBooks = new ArrayList<String>();
    }

    public String getLibrary_number(){
        return library_number;
    }
    public String getPassword(){
        return password;
    }
    public void addBooks(String name){
        checkedOutBooks.add(name);
    }

    public static boolean isValidUser(Customer loggedCustomer ,ArrayList<Customer> customerDetails) {
        for( Customer customer: customerDetails ){
            if((customer.getLibrary_number().equals(loggedCustomer.getLibrary_number()))&&
                    (customer.getPassword().equals(loggedCustomer.getPassword()))){
                return true;
            }
        }
        return false;
    }

    public static Customer getCustomerByNumber(String number, ArrayList<Customer> customers){

        for( Customer customer: customers ){
            if(number.equals(customer.getLibrary_number()))
                return customer;
        }
        return null;
    }

    public  String toString() {
        return ( "You are logged in as "+ name +"\nContact Details: "+ emailID +"\t\tPhone Number: "+phone_Number+"\n"
        +"Checked Out Books\n"+ getAllCheckOutBooks());
    }

    public String getAllCheckOutBooks(){
        String allBookDetails = "";
        for ( int index = 0 ;index < checkedOutBooks.size();index++){
            allBookDetails += checkedOutBooks.get(index)+"\n";
        }
        return allBookDetails;
    }
}

